package com.yugao.fintech.antelope.infra.file.controller;

import com.yugao.fintech.antelope.infra.file.service.MediaMaterialService;
import com.yugao.fintech.antelope.infra.group.service.DataGroupService;
import com.yugao.fintech.antelope.infra.module.group.model.rqrs.DataGroupDeleteReq;
import com.yugao.fintech.antelope.infra.module.group.model.rqrs.DataGroupSaveReq;
import com.yugao.fintech.antelope.infra.module.group.model.rqrs.DataGroupUpdateReq;
import com.yugao.fintech.antelope.base.model.enums.DataGroupBizTypeEnum;
import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.framework.core.response.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.Collections;
import java.util.List;

/**
 * 素材组
 */
@Api(tags = "素材数据组")
@RestController
@RequestMapping("/materialGroup")
public class MaterialGroupController {
    @Autowired
    private DataGroupService dataGroupService;
    @Autowired
    private MediaMaterialService mediaMaterialService;

    @ApiOperation(value = "保存素材组")
    @PostMapping("/save")
    @RamResource(action = "material:group:save", name = "保存素材组", type = ActionType.WRITE)
    public Resp<?> saveDataGroup(@RequestBody DataGroupSaveReq req) {
        req.setBizType(DataGroupBizTypeEnum.MATERIAL.getType());
        return Resp.ok(dataGroupService.saveGroup(req));
    }

    @ApiOperation(value = "更新素材组")
    @PostMapping("/update")
    @RamResource(action = "material:group:update", name = "更新素材组", type = ActionType.WRITE)
    public Resp<?> updateDataGroup(@RequestBody DataGroupUpdateReq req) {
        return Resp.ok(dataGroupService.updateGroup(req));
    }

    @ApiOperation(value = "批量删除素材组")
    @DeleteMapping("/batchDelete")
    @RamResource(action = "material:group:delete", name = "删除素材组", type = ActionType.WRITE)
    public Resp<?> batchDeleteDataGroup(@RequestParam(value = "ids") List<Long> ids) {
        DataGroupDeleteReq req = new DataGroupDeleteReq();
        req.setBizType(DataGroupBizTypeEnum.MATERIAL.getType());
        req.setIds(ids);
        return Resp.ok(mediaMaterialService.deleteGroup(req));
    }

    @ApiOperation(value = "删除素材组")
    @DeleteMapping("/delete")
    @RamResource(action = "material:group:delete", name = "删除素材组", type = ActionType.WRITE)
    public Resp<?> deleteDataGroup(@RequestParam(value = "id") Long id) {
        DataGroupDeleteReq req = new DataGroupDeleteReq();
        req.setBizType(DataGroupBizTypeEnum.MATERIAL.getType());
        req.setIds(Collections.singletonList(id));
        return Resp.ok(mediaMaterialService.deleteGroup(req));
    }
}
